﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace InterviewQuestions
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        private void ClearToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
        }

        private void AnagramsButton_Click(object sender, EventArgs e)
        {
            Anagrams.Anagrams o = new Anagrams.Anagrams();
            richTextBox1.AppendText(o.Execute("12%dog", "12%god").ToString());
            richTextBox1.AppendText(o.Execute("dog", "goD").ToString());
            richTextBox1.AppendText(o.Execute("ggg", "god").ToString());
            richTextBox1.AppendText(o.Execute(string.Empty, "god").ToString());
            richTextBox1.AppendText(o.Execute("g", "a").ToString());

            richTextBox1.AppendText(o.ExecuteQuicksort("dog", "god").ToString());
            richTextBox1.AppendText(o.ExecuteQuicksort("ggg", "god").ToString());
            richTextBox1.AppendText(o.ExecuteQuicksort(string.Empty, "god").ToString());
            richTextBox1.AppendText(o.ExecuteQuicksort("g", "a").ToString());
        }

        private void CopyLinkedListButton_Click(object sender, EventArgs e)
        {
            QQ.InterviewQuestions.LinkedList.CopyLinkedListRandom o = new QQ.InterviewQuestions.LinkedList.CopyLinkedListRandom();
            o.Execute();
        }

        private void RandomShuffleButton_Click(object sender, EventArgs e)
        {
            richTextBox1.AppendText("\r\n");

            QQ.InterviewQuestions.RandomShuffle.RandomShuffle o = new QQ.InterviewQuestions.RandomShuffle.RandomShuffle(52);
            int[] cards = o.Execute();

            foreach (int item in cards)
            {
                richTextBox1.AppendText(item.ToString() + "; ");
            }
        }

        private void LargestSumButton_Click(object sender, EventArgs e)
        {
            LargestSum.LargestSum o = new LargestSum.LargestSum();
            int[] input = { -6, -8, -3, -2, -4 };
            int maxSum = o.Execute(input);
            richTextBox1.AppendText(maxSum.ToString() + "\r\n");
        }

        private void FibbonacciButton_Click(object sender, EventArgs e)
        {
            QQ.InterviewQuestions.Fibbonacci.Fibbonacci o = new QQ.InterviewQuestions.Fibbonacci.Fibbonacci();
            Console.WriteLine(o.Execute(6));
            Console.WriteLine(o.ExecuteNonRecursive(6));
        }

        private void ShiftedArrayButton_Click(object sender, EventArgs e)
        {
            QQ.InterviewQuestions.ShiftedArray.ShiftedArray o = new QQ.InterviewQuestions.ShiftedArray.ShiftedArray();
            //int[] a = { 20, 30, 45, -9, -4, 0, 12 };
            //int[] a = { 30, 45, 49, -50 };
            int[] a = { 5 };
            richTextBox1.AppendText(o.FindMinIndexPartialSorted(a).ToString() + "\r\n");
        }

        private void BinarySearchButton_Click(object sender, EventArgs e)
        {
            QQ.InterviewQuestions.BinarySearch.BinarySearch o = new QQ.InterviewQuestions.BinarySearch.BinarySearch();

            int[] a = { -34, 2, 2, 3, 14, 50 };
            richTextBox1.AppendText(o.Execute(a, 14) + "\r\n");
            richTextBox1.AppendText(o.ExecuteRecursive(a, 14) + "\r\n");
            richTextBox1.AppendText(o.FindClosestNumberIndex(a, 49) + "\r\n");
        }

        private void BSTButton_Click(object sender, EventArgs e)
        {
            QQ.InterviewQuestions.BinarySearchTree.BinarySearchTree o = new QQ.InterviewQuestions.BinarySearchTree.BinarySearchTree();
            o.Initialize();
            o.PreorderTraversal();
            Console.WriteLine();
            o.InorderTraversal();
            Console.WriteLine();
            o.PostorderTraversal();
            Console.WriteLine();
            o.NonRecursiveTraversalInorder();
        }

        private void SortedMatrixButton_Click(object sender, EventArgs e)
        {
            QQ.InterviewQuestions.SortedMatrix.SortedMatrix o = new QQ.InterviewQuestions.SortedMatrix.SortedMatrix();
            Console.WriteLine(o.Find(50));
        }

        private void FindMissingIntegerButton_Click(object sender, EventArgs e)
        {
            QQ.InterviewQuestions.Array.FindMissingInteger o = new QQ.InterviewQuestions.Array.FindMissingInteger();
            Console.WriteLine(o.Find());
        }

        private void SplitArrayButton_Click(object sender, EventArgs e)
        {
            QQ.InterviewQuestions.Array.SplitArray o = new QQ.InterviewQuestions.Array.SplitArray();
            int[] a = { 2, 4, 5, 8, 1, 9, 7 };

            foreach (int item in a)
            {
                 Console.Write(item);
            }
            Console.WriteLine();
            foreach (int item in o.Execute(a))
            {
                 Console.Write(item);
            }
        }

        private void CircularLinkedListButton_Click(object sender, EventArgs e)
        {
            QQ.InterviewQuestions.LinkedList.CircularLinkedList o = new QQ.InterviewQuestions.LinkedList.CircularLinkedList();
            QQ.InterviewQuestions.LinkedList.Node list = o.GenerateCircularLinkedList();
            Console.WriteLine(o.IsCircular(list));
        }

        private void SortLinkListButton_Click(object sender, EventArgs e)
        {
            QQ.InterviewQuestions.Sorting.QSort o = new QQ.InterviewQuestions.Sorting.QSort();
            QQ.InterviewQuestions.LinkedList.Node head = new QQ.InterviewQuestions.LinkedList.Node(2);
            head.Next = new QQ.InterviewQuestions.LinkedList.Node(1);
            head.Next.Next = new QQ.InterviewQuestions.LinkedList.Node(4);
            head.Next.Next.Next = new QQ.InterviewQuestions.LinkedList.Node(3);
            head.Next.Next.Next.Next = new QQ.InterviewQuestions.LinkedList.Node(0);
            //QQ.InterviewQuestions.LinkedList.NodeList list = new QQ.InterviewQuestions.LinkedList.NodeList();
            //list.Append(head);
            o.Sort(head);
        }

        private void RemoveDuplicateButton_Click(object sender, EventArgs e)
        {
            QQ.InterviewQuestions.String.StringProcess o = new QQ.InterviewQuestions.String.StringProcess();
            string s = "AABBBCCCC";
            o.RemoveDuplicateCharactersFromSortedString(s);
            Console.WriteLine(s);
        }
    }
}
